package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        /*使用JDBC操作数据库基本流程：
        1.加载驱动
        2.
         */
        Class.forName("com.mysql.cj.jdbc.Driver");//这个是MySQL的
        //2与数据库链接
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"
        );
        System.out.println("与数据库建立连接");
        //3创建语句执行对象
        Statement statement = connection.createStatement();
        //4执行创建操作
        String sql="CREATE TABLE userinfo(\n" +
                "    id INT PRIMARY KEY AUTO_INCREMENT,\n" +
                "    username VARCHAR(32),\n" +
                "    password VARCHAR(32),\n" +
                "    nickname VARCHAR(32),\n" +
                "    age INT(3)\n" +
                ")";
        statement.execute(sql);
        System.out.println("创建成功");
        connection.close();
    }
}
